Uec3.PackageBrowserWindow = Ext.extend(Ext.app.Module,{
	id: 'packageBrowser',
   /*
    * Initialize this module.
    * This function is called at startup (page load/refresh).
    */
   init : function(initParams){
   
   },
 
   detailPackage : function(packageId){
   	
   },
   
   editPackage : function(packageId){
   	
   },
   
   getComponent:function(){
   	    var _this = this;
   		var isGift_Store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'package_isGift'});
   	    var isGift_combox = getDictionaryComboBox(isGift_Store,'local','isGift','','isGift','','100%');
   	
   	    var giftCondition_Store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'package_giftCondition'});
   	    var giftCondition_combox = getDictionaryComboBox(giftCondition_Store,'local','giftCondition','','giftCondition','','100%');
   	
   		var package_store = new Ext.data.JsonStore({
   	          url:Uec3.App.Constants.homeUrl + '/companyPackage/searchAllPackage.do',
   	          root:'root', 
   	          totalProperty:'totalProperty',
   	          fields:['id','code','name','price','description','gmtBegin','gmtEnd','isGift','giftCondition'],
   	          listeners:{
   	            'beforeload':function(){
                    Ext.MessageBox.wait("正在加载数据...","提示");
                 }
   	          }
   	    });
   	
   	    var selModel = new Ext.grid.RowSelectionModel({
   	           moveEditorOnEnter:true,
   	           singleSelect :true
   	    });
   	    
   	    var actionCol = {
					header : "操作",					
					sortable : false,
					dataIndex:'id',
					width:80,
					renderer : this.moduleActionRenderer([
					           {func : "detailPackage",desc : "查看"},
					           {func : "editPackage",desc : "编辑"}
		            ])
		};
   	    
		 	//创建工具栏组件
		  var toolbar = new Ext.Toolbar({
		     items:[
			    {text : '增加套餐',iconCls : 'icon-add',itemId:'addPcakge',handler:addPackage}			   		 
		     ]
		  });
		
   	    var colModel = new Ext.grid.ColumnModel({
   	         columns:[
          		   	new Ext.grid.RowNumberer(),  
          		   	actionCol,
      		 	   	{header:'套餐编号',dataIndex:'code',width:60},
      		 		{header:'套餐名称',dataIndex:'name',width:90},
      		 		{header:'价格',dataIndex:'price',width:80},
      		 		{header:'有效开始时间',dataIndex:'gmtBegin',width:80},
      		 		{header:'有效结束时间',dataIndex:'gmtEnd',width:80},
      		 		{header:'是否免费',dataIndex:'isGift',width:50,renderer:Ext.util.Format.comboRenderer(isGift_combox)},
      		 		{header:'免费条件',dataIndex:'giftCondition',width:60,renderer:Ext.util.Format.comboRenderer(giftCondition_combox)},
      		 		{header:'描述',dataIndex:'description',width:180}     		 		      		 		
          		],
          		defaults: {
          			menuDisabled: true         
       			}
   	    });
   	    
   		var package_grid = new Ext.grid.GridPanel({
   		     viewConfig:{forceFit:true,scrollOffset:20},	   	   
	   	   	 autoScroll : true,
	   	   	 loadMask:{mag:'数据加载中,请稍后....'},
	   	   	 titleCollapse:true,
	         colModel:colModel,	         
	         selModel:selModel,
	         store:package_store,	           
	         columnLines :true,
	         tbar:toolbar,
	         bbar: new Ext.PagingToolbar({
		            pageSize:20,
	                store:package_store,
	                displayInfo: true,
	                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                    emptyMsg: "没有记录",                   
                    listeners:{
                        beforechange:function(){
                      		 Ext.MessageBox.wait("正在加载数据...","提示");	                     
                        },
                        change:function(){
                            Ext.MessageBox.hide();
                        }
                    }
		     }) 
   		});
   		
   		function addPackage(){
   		   _this.app.getDesktop().launchWindow("packageAdd");
   		}
   		
   		function init(){
   			isGift_Store.load();
   			giftCondition_Store.load();
   			package_store.baseParams={start:0,limit:20};
   			package_store.load({
   				callback:function(records,options,success){
   					if(success){
	                 	var total=records.length;
	                 	if(Ext.isEmpty(total)){
	                   		Ext.MessageBox.alert("提示","未找到相关记录");
	                 	}
	              	}else{
	                 	Ext.MessageBox.alert("提示",this.reader.jsonData.msg);
	             	}
   				}
   			});  		
   		}
   		
   		init();
   		return package_grid;
   },
   
   /**
	* Create this modules window here.
	*/
   createWindow : function(params){
    	var desktop = this.app.getDesktop();
        var win = desktop.getWindow('packageBrowser');
        if (!win) {
			win = desktop.createWindow({
				        id : "packageAdd",
						title : '套餐浏览',
						width : 1000,
						height : 500,
						iconCls : 'acc-icon',
					    minWidth:1000,
						maximizable : true,
						//resizable:false,
						maximized:true,
						//autoScroll : true,
						constrainHeader : true,
						taskbuttonTooltip : "套餐浏览",
						//layout : "fit",
						items : [this.getComponent(params)]
					});
		}
	  win.get(0).setHeight(win.getHeight()-32);
      win.show(); 
      win.on('resize',function(win,width,height){
      	  win.get(0).setHeight(height-35);
      });         
   }
});